home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / tcp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  8.5 KB  |  259 lines

  1. /* TCP implementation. Follows RFC 793 as closely as possible */
  2. #ifndef    NULLTCB
  3.  
  4. #include "global.h"
  5. #include "netuser.h"
  6. #include "timer.h"
  7. #include "internet.h"
  8.  
  9. #define    DEF_WND    2048    /* Default receiver window */
  10. #define    NTCB    19    /* # TCB hash table headers */
  11. #define    RTTCACHE 16    /* # of TCP round-trip-time cache entries */
  12. #define    DEF_MSS    512    /* Default maximum segment size */
  13. #define    DEF_RTT    5000    /* Initial guess at round trip time (5 sec) */
  14. #define    MSL2    30    /* Guess at two maximum-segment lifetimes */
  15.  
  16. extern int32 Clock;
  17. #define    geniss()    ((int32)Clock << 18)    /* Increment clock at 4.5 Mbytes/sec */
  18.  
  19. /* Round trip timing parameters */
  20. #define    AGAIN    8    /* Average RTT gain = 1/8 */
  21. #define    LAGAIN    3    /* Log2(AGAIN) */
  22. #define    DGAIN    4    /* Mean deviation gain = 1/4 */
  23. #define    LDGAIN    2    /* log2(DGAIN) */
  24.  
  25. /* TCP segment header -- internal representation
  26.  * Note that this structure is NOT the actual header as it appears on the
  27.  * network (in particular, the offset and checksum fields are missing).
  28.  * All that knowledge is in the functions ntohtcp() and htontcp() in tcpsubr.c
  29.  */
  30. struct tcp {
  31.     int16 source;    /* Source port */
  32.     int16 dest;    /* Destination port */
  33.     int32 seq;    /* Sequence number */
  34.     int32 ack;    /* Acknowledgment number */
  35.     struct {
  36.         char urg;
  37.         char ack;
  38.         char psh;
  39.         char rst;
  40.         char syn;
  41.         char fin;
  42.     } flags;
  43.     int16 wnd;    /* Receiver flow control window */
  44.     int16 up;    /* Urgent pointer */
  45.     int16 mss;    /* Optional max seg size */
  46. };
  47. /* TCP options */
  48. #define    EOL_KIND    0
  49. #define    NOOP_KIND    1
  50. #define    MSS_KIND    2
  51.  
  52. #define    TCPLEN        20
  53. #define    MSS_LENGTH    4
  54. /* Resequencing queue entry */
  55. struct reseq {
  56.     struct reseq *next;    /* Linked-list pointer */
  57.     struct tcp seg;        /* TCP header */
  58.     struct mbuf *bp;    /* data */
  59.     int16 length;        /* data length */
  60.     char tos;        /* Type of service */
  61. };
  62. #define    NULLRESEQ    (struct reseq *)0
  63.  
  64. /* TCP connection control block */
  65. struct tcb {
  66.     struct tcb *prev;    /* Linked list pointers for hash table */
  67.     struct tcb *next;
  68.  
  69.     struct connection conn;
  70.  
  71.     char state;    /* Connection state */
  72.  
  73. /* These numbers match those defined in the MIB for TCP connection state */
  74. #define    TCP_CLOSED        1
  75. #define    TCP_LISTEN        2
  76. #define    TCP_SYN_SENT        3
  77. #define    TCP_SYN_RECEIVED    4
  78. #define    TCP_ESTABLISHED        5
  79. #define    TCP_FINWAIT1        6
  80. #define    TCP_FINWAIT2        7
  81. #define    TCP_CLOSE_WAIT        8
  82. #define    TCP_LAST_ACK        9
  83. #define    TCP_CLOSING        10
  84. #define    TCP_TIME_WAIT        11
  85.  
  86.     char reason;        /* Reason for closing */
  87. #define    NORMAL        0    /* Normal close */
  88. #define    RESET        1    /* Reset by other end */
  89. #define    TIMEOUT        2    /* Excessive retransmissions */
  90. #define    NETWORK        3    /* Network problem (ICMP message) */
  91.  
  92. /* If reason == NETWORK, the ICMP type and code values are stored here */
  93.     char type;
  94.     char code;
  95.  
  96.     /* Send sequence variables */
  97.     struct {
  98.         int32 una;    /* First unacknowledged sequence number */
  99.         int32 nxt;    /* Next sequence num to be sent for the first time */
  100.         int32 ptr;    /* Working transmission pointer */
  101.         int32 wl1;    /* Sequence number used for last window update */
  102.         int32 wl2;    /* Ack number used for last window update */
  103.         int16 wnd;    /* Other end's offered receive window */
  104.         int16 up;    /* Send urgent pointer */
  105.     } snd;
  106.     int32 iss;        /* Initial send sequence number */
  107.     int32 resent;        /* Count of bytes retransmitted */
  108.     int16 cwind;        /* Congestion window */
  109.     int16 ssthresh;        /* Slow-start threshold */
  110.  
  111.     /* Receive sequence variables */
  112.     struct {
  113.         int32 nxt;    /* Incoming sequence number expected next */
  114.         int16 wnd;    /* Our offered receive window */
  115.         int16 up;    /* Receive urgent pointer */
  116.     } rcv;
  117.     int32 irs;        /* Initial receive sequence number */
  118.     int32 rerecv;        /* Count of duplicate bytes received */
  119.     int16 mss;        /* Maximum segment size */
  120.  
  121.     int16 window;        /* Receiver window and send queue limit */
  122.  
  123.     void (*r_upcall) __ARGS((struct tcb *tcb,int cnt));
  124.         /* Call when "significant" amount of data arrives */
  125.     void (*t_upcall) __ARGS((struct tcb *tcb,int cnt));
  126.         /* Call when ok to send more data */
  127.     void (*s_upcall) __ARGS((struct tcb *tcb,int old,int new));
  128.         /* Call when connection state changes */
  129.     struct {        /* Control flags */
  130.         char force;    /* We owe the other end an ACK or window update */
  131.         char clone;    /* Server-type TCB, cloned on incoming SYN */
  132.         char retran;    /* A retransmission has occurred */
  133.         char active;    /* TCB created with an active open */
  134.         char synack;    /* Our SYN has been acked */
  135.         char rtt_run;    /* We're timing a segment */
  136.     } flags;
  137.     char tos;        /* Type of service (for IP) */
  138.     char backoff;        /* Backoff interval */
  139.  
  140.     struct mbuf *rcvq;    /* Receive queue */
  141.     struct mbuf *sndq;    /* Send queue */
  142.     int16 rcvcnt;        /* Count of items on rcvq */
  143.     int16 sndcnt;        /* Number of unacknowledged sequence numbers on
  144.                  * sndq. NB: includes SYN and FIN, which don't
  145.                  * actually appear on sndq!
  146.                  */
  147.  
  148.     struct reseq *reseq;    /* Out-of-order segment queue */
  149.     struct timer timer;    /* Retransmission timer */
  150.     int32 rtt_time;        /* Stored clock values for RTT */
  151.     int32 rttseq;        /* Sequence number being timed */
  152.     int32 srtt;        /* Smoothed round trip time, milliseconds */
  153.     int32 mdev;        /* Mean deviation, milliseconds */
  154.  
  155.     int user;        /* User parameter (e.g., for mapping to an
  156.                  * application control block
  157.                  */
  158. };
  159. #define    NULLTCB    (struct tcb *)0
  160. /* TCP round-trip time cache */
  161. struct tcp_rtt {
  162.     int32 addr;        /* Destination IP address */
  163.     int32 srtt;        /* Most recent SRTT */
  164.     int32 mdev;        /* Most recent mean deviation */
  165. };
  166. #define    NULLRTT    (struct tcp_rtt *)0
  167. extern struct tcp_rtt Tcp_rtt[];
  168.  
  169. /* TCP statistics counters */
  170. struct tcp_stat {
  171.     int16 runt;        /* Smaller than minimum size */
  172.     int16 checksum;        /* TCP header checksum errors */
  173.     int16 conout;        /* Outgoing connection attempts */
  174.     int16 conin;        /* Incoming connection attempts */
  175.     int16 resets;        /* Resets generated */
  176.     int16 bdcsts;        /* Bogus broadcast packets */
  177. };
  178. extern struct mib_entry Tcp_mib[];
  179. #define    tcpRtoAlgorithm    Tcp_mib[1].value.integer
  180. #define    tcpRtoMin    Tcp_mib[2].value.integer
  181. #define    tcpRtoMax    Tcp_mib[3].value.integer
  182. #define    tcpMaxConn    Tcp_mib[4].value.integer
  183. #define    tcpActiveOpens    Tcp_mib[5].value.integer
  184. #define tcpPassiveOpens    Tcp_mib[6].value.integer
  185. #define    tcpAttemptFails    Tcp_mib[7].value.integer
  186. #define    tcpEstabResets    Tcp_mib[8].value.integer
  187. #define    tcpCurrEstab    Tcp_mib[9].value.integer
  188. #define    tcpInSegs    Tcp_mib[10].value.integer
  189. #define    tcpOutSegs    Tcp_mib[11].value.integer
  190. #define    tcpRetransSegs    Tcp_mib[12].value.integer
  191. #define    tcpInErrs    Tcp_mib[14].value.integer
  192. #define    tcpOutRsts    Tcp_mib[15].value.integer
  193. #define    tcpChkSumErrs    Tcp_mib[16].value.integer
  194. #define    NUMTCPMIB    16
  195.  
  196. extern struct tcb *Tcbs[];
  197. extern int16 Tcp_mss;
  198. extern int16 Tcp_window;
  199. extern int32 Tcp_irtt;
  200. extern int Tcp_trace;
  201. extern char *Tcpstates[];
  202. extern char *Tcpreasons[];
  203.  
  204. /* In tcpcmd.c: */
  205. void st_tcp __ARGS((struct tcb *tcb));
  206.  
  207. /* In tcphdr.c: */
  208. struct mbuf *htontcp __ARGS((struct tcp *tcph,struct mbuf *data,
  209.     struct pseudo_header *ph));
  210. int ntohtcp __ARGS((struct tcp *tcph,struct mbuf **bpp));
  211.  
  212. /* In tcpin.c: */
  213. void reset __ARGS((struct ip *ip,struct tcp *seg));
  214. void send_syn __ARGS((struct tcb *tcb));
  215. void tcp_input __ARGS((struct mbuf *bp,struct ip *ip,int rxbroadcast));
  216. void tcp_icmp __ARGS((int32 source,int32 dest,char type,char code,struct mbuf **bpp));
  217.  
  218. /* In tcpsubr.c: */
  219. void close_self __ARGS((struct tcb *tcb,int reason));
  220. struct tcb *create_tcb __ARGS((struct connection *conn));
  221. void link_tcb __ARGS((struct tcb *tcb));
  222. struct tcb *lookup_tcb __ARGS((struct connection *conn));
  223. void rtt_add __ARGS((int32 addr,int32 rtt));
  224. struct tcp_rtt *rtt_get __ARGS((int32 addr));
  225. int seq_ge __ARGS((int32 x,int32 y));
  226. int seq_gt __ARGS((int32 x,int32 y));
  227. int seq_le __ARGS((int32 x,int32 y));
  228. int seq_lt __ARGS((int32 x,int32 y));
  229. int seq_within __ARGS((int32 x,int32 low,int32 high));
  230. void setstate __ARGS((struct tcb *tcb,int newstate));
  231. void unlink_tcb __ARGS((struct tcb *tcb));
  232.  
  233. /* In tcpout.c: */
  234. void tcp_output __ARGS((struct tcb *tcb));
  235.  
  236. /* In tcptimer.c: */
  237. int backoff __ARGS((int n));
  238. void tcp_timeout __ARGS((void *p));
  239.  
  240. /* In tcpuser.c: */
  241. int close_tcp __ARGS((struct tcb *tcb));
  242. int del_tcp __ARGS((struct tcb *tcb));
  243. int kick __ARGS((int32 addr));
  244. int kick_tcp __ARGS((struct tcb *tcb));
  245. struct tcb *open_tcp __ARGS((struct socket *lsocket,struct socket *fsocket,
  246.     int mode,int16 window,
  247.     void (*r_upcall) __ARGS((struct tcb *tcb,int cnt)),
  248.     void (*t_upcall) __ARGS((struct tcb *tcb,int cnt)),
  249.     void (*s_upcall) __ARGS((struct tcb *tcb,int old,int new)),
  250.     int tos,int user));
  251. int recv_tcp __ARGS((struct tcb *tcb,struct mbuf **bpp,int16 cnt));
  252. void reset_all __ARGS((void));
  253. void reset_tcp __ARGS((struct tcb *tcb));
  254. int send_tcp __ARGS((struct tcb *tcb,struct mbuf *bp));
  255. char *tcp_port __ARGS((int16 n));
  256. int tcpval __ARGS((struct tcb *tcb));
  257.  
  258. #endif    /* NULLTCB */
  259.